
package com.huaweicloud.haydn.delivercore.agent.common.exception;

import lombok.Getter;
import lombok.NoArgsConstructor;

import org.springframework.http.HttpStatus;

/**
 * @since 2022-09-24
 */
@NoArgsConstructor
@Getter
public class BusinessException extends RuntimeException {
    private static final long serialVersionUID = 1L;

    private HttpStatus httpStatus = HttpStatus.INTERNAL_SERVER_ERROR;

    private String errCode;

    private String errMsg;

    public BusinessException(BusinessErrorEnum errorEnum) {
        super(errorEnum.getErrMsg());
        errCode = errorEnum.getErrCode();
        errMsg = errorEnum.getErrMsg();
        httpStatus = errorEnum.getHttpStatus();
    }

    public BusinessException(BusinessErrorEnum errorEnum, String msg) {
        super(msg);
        errCode = errorEnum.getErrCode();
        errMsg = msg;
        httpStatus = errorEnum.getHttpStatus();
    }

    public BusinessException(String code, String msg, HttpStatus status) {
        super(msg);
        errCode = code;
        errMsg = msg;
        httpStatus = status;
    }

    @Override
    public String toString() {
        return "BusinessException{" + "httpStatus='" + httpStatus + '\'' + ", errCode='" + errCode + '\'' + ", errMsg='"
            + errMsg + '\'' + '}';
    }
}
